package com.eci.common.asset.core;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;

import java.util.Collections;
import java.util.List;

 
public class Page {
	
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@ApiModelProperty(value="第几页",example="1")
	private int pageNum = 1;
	
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@ApiModelProperty(value="每页记录数",example="20")
	private int pageSize = 20;
	
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@ApiModelProperty(value="排序字段",example="code")
	private String sortField;
	
	@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
	@ApiModelProperty(value="排序方式",example="asc")
	private String sortWay;

	@JsonProperty(access = JsonProperty.Access.READ_ONLY)
	@JsonInclude(Include.NON_NULL)
	@ApiModelProperty(value="总的记录数",hidden = true)
	private Integer total = null;
	
	@JsonProperty(access = JsonProperty.Access.READ_ONLY)
	@JsonInclude(Include.NON_NULL)
	@ApiModelProperty(value="记录集合",hidden = true)
	private List<?> results = null;
	
	 

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getSortField() {
		return sortField;
	}

	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public String getSortWay() {
		return sortWay;
	}

	public void setSortWay(String sortWay) {
		this.sortWay = sortWay;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public List<?> getResults() {
		return results;
	}

	public void setResults(List<?> results) {
		this.results = results;
	}
	 
	
	public Page() {

	}

	private Page(Integer total, List<?> results) {
		this.total = total;
		this.results = results;
	}
	
	 
	
	public static Page newPage(Integer total, List<?> results) {
		return new Page(total, results);
	}

	public static Page newPage(List<?> results) {
		return new Page(results.size(), results);
	}
 
	
	public static Page empty() {
		return Singletons.EMPTY;
	}
	
	
	private static class Singletons { 
		private static final Page EMPTY = new Page(0, Collections.EMPTY_LIST); 
	}

}